package com.tom.ssm.jetty;

import org.eclipse.jetty.server.Server;

public class StartServer {
	public static final int PORT = 8080;
	public static final String CONTEXT = "/tom-ssm";
	public static final String[] TLD_JAR_NAMES = new String[] { "sitemesh", "spring-webmvc", "shiro-web",
			"springside-core" };

	public static void main(String[] args) throws Exception {
		// 设定Spring的profile
		Profiles.setProfileAsSystemProperty(Profiles.DEVELOPMENT);
		// 启动Jetty
		Server server = JettyFactory.createServerInSource(PORT, CONTEXT);
		JettyFactory.setTldJarNames(server, TLD_JAR_NAMES);
		try {
			long startTime = System.currentTimeMillis();
			server.start();
			server.setAttribute("org.eclipse.jetty.server.Request.maxFormContentSize", 2000000000);
			long endTime = System.currentTimeMillis();
			System.out.println("[INFO] Server running at http://localhost:" + PORT + CONTEXT);
			System.out.println("[HINT] Hit Enter to reload the application quickly");
			System.out.println("[INFO] Server startup in " + (endTime - startTime) + " ms");
			// 等待用户输入回车重载应用.
			while (true) {
				char c = (char) System.in.read();
				if (c == '\n') {
					JettyFactory.reloadContext(server);
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
			System.exit(-1);
		}
	}
}
